# my_features_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class MyFeaturesPage:
    # 初始化 MyFeaturesPage 对象
    def __init__(self, driver):
        self.driver = driver
        self.url = 'http://example.com/my-features'
        self.user_info_locator = (By.ID, 'user-info')
        self.edit_profile_button_locator = (By.ID, 'edit-profile')
        self.order_history_locator = (By.ID, 'order-history')
        self.address_book_locator = (By.ID, 'address-book')
        self.logout_button_locator = (By.ID, 'logout')

    # 导航至我的功能页面
    def navigate(self):
        self.driver.get(self.url)

    # 获取用户信息
    def get_user_info(self):
        return self.driver.find_element(*self.user_info_locator).text

    # 点击编辑资料按钮
    def click_edit_profile(self):
        edit_button = self.driver.find_element(*self.edit_profile_button_locator)
        edit_button.click()

    # 获取订单历史
    def get_order_history(self):
        return self.driver.find_element(*self.order_history_locator).text

    # 获取地址簿
    def get_address_book(self):
        return self.driver.find_element(*self.address_book_locator).text

    # 点击登出按钮
    def click_logout(self):
        logout_button = self.driver.find_element(*self.logout_button_locator)
        logout_button.click()

    # 等待页面加载完成
    def wait_for_page_to_load(self):
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(self.user_info_locator)
        )